// pages/menpiao/menpiao.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    type: 'a',
    recommendType: {
      a: 0,
      b: 1,
      c: 2,
      d: 3
    },
    list1: [],
    list2: [],
    list3: [],
    list4: []
  },
  

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      type: options.type || "a"
    })
    this.getRecommendList()
  },
  onChange(e) {
    this.setData({
      type: e.detail.name
    })
    this.getRecommendList();
  },
  /** 获取 */
  getRecommendList() {
    let type = this.data.recommendType[this.data.type];
    let params = {
      type: type
    }
    if(type === 0) {
      params.hot = 1;
    }
    wx.$http.post(wx.$api.fetchRecommendList, params).then(res => {
      console.log(res);
      let _res = res || [];
      switch(type) {
        case 0:
          this.setData({
            list1: _res
          })
          break;
        case 1:
          this.setData({
            list2: _res
          })
          break;
        case 2:
          this.setData({
            list3: _res
          })
          break;
        case 3:
          this.setData({
            list4: _res
          })
          break;
      }
    })
    .catch(err => {
      console.log(err)
      wx.showToast({
        title: err.message,
      })
    })
  },
  /**跳转到详情页 */
  goToDetail(e) {
    console.log(e)
    let dataset = e.currentTarget.dataset;
    let url = "";
    if(dataset.type === 1) {
      url = "/pages/menpiao_neiye/menpiao_neiye";
    } else if(dataset.type === 2) {
      url = "/pages/yiriyou_neiye/yiriyou_neiye";
    } else if(dataset.type === 3) {
      url = "/pages/menpiao_neiye/menpiao_neiye";
    }
    wx.navigateTo({
      url: url + "?id=" + dataset.id
    })
  }
})